from datetime import datetime

from langfuse.openai import openai  # OpenAI integration
from langfuse.decorators import observe, langfuse_context

# 加载 .env 到环境变量
from dotenv import load_dotenv, find_dotenv

_ = load_dotenv(find_dotenv())


@observe()
def run():
    now = datetime.now()
    langfuse_context.update_current_trace(
        name="RecordMeta",  # 在本次的trac里面添加名称
        user_id="bml",  # 在本次的trace添加用户id
        metadata={"id": 1, "name": "bml", "time": now.strftime("%d/%m/%Y %H:%M:%S")}  # 添加元数据
    )
    return openai.chat.completions.create(
        model="gpt-3.5-turbo",
        messages=[
            {"role": "user", "content": "对我说Hello, World!"}
        ],
    ).choices[0].message.content


print(run())
